home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / ulog / RCS / Ulog_GetAllLogins.c,v < prev    next >
Encoding:
Text File  |  1989-01-13  |  4.7 KB  |  206 lines

  1. head     1.4;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.4
  10. date     89.01.13.11.49.34;  author douglis;  state Exp;
  11. branches ;
  12. next     1.3;
  13.  
  14. 1.3
  15. date     88.09.15.10.16.34;  author douglis;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     88.09.13.16.43.33;  author douglis;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     88.08.14.15.11.35;  author douglis;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @Retrieve multiple login records from the login database.
  32. @
  33.  
  34.  
  35. 1.4
  36. log
  37. @tell Db_Open how many records to buffer.
  38. @
  39. text
  40. @/* 
  41.  * Ulog_GetAllLogins.c --
  42.  *
  43.  *    Source code for the Ulog_GetAllLogins procedure.
  44.  *
  45.  * Copyright 1988 Regents of the University of California
  46.  * Permission to use, copy, modify, and distribute this
  47.  * software and its documentation for any purpose and without
  48.  * fee is hereby granted, provided that the above copyright
  49.  * notice appear in all copies.  The University of California
  50.  * makes no representations about the suitability of this
  51.  * software for any purpose.  It is provided "as is" without
  52.  * express or implied warranty.
  53.  */
  54.  
  55. #ifndef lint
  56. static char rcsid[] = "$Header: /sprite/src/lib/c/ulog/RCS/Ulog_GetAllLogins.c,v 1.3 88/09/15 10:16:34 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  57. #endif not lint
  58.  
  59.  
  60. #include <ulog.h>
  61. #include "ulogInt.h"
  62.  
  63.  
  64. /*
  65.  *----------------------------------------------------------------------
  66.  *
  67.  * Ulog_GetAllLogins --
  68.  *
  69.  *    Get the records for all valid login records, up to the number of
  70.  *     records specified.  If the records correspond to a machine
  71.  *    that is down, they will still be returned and it is the responsibility
  72.  *     of the caller to verify the status of each machine.
  73.  *
  74.  * Results:
  75.  *    -1 indicates an error, in which case errno indicates more details.
  76.  *    On success, the number of structures being returned in *dataPtr
  77.  *    is returned as the value of the function.
  78.  *    *locPtr is set to the next location to be searched.
  79.  *
  80.  * Side effects:
  81.  *    The database file is opened for reading, locked, and later closed.
  82.  *
  83.  *----------------------------------------------------------------------
  84.  */
  85.  
  86. #define NUMBUF 100
  87.  
  88. int
  89. Ulog_GetAllLogins(numEntries, locPtr, dataPtr)
  90.     int numEntries;        /* number of structures in *dataPtr */
  91.     int *locPtr;        /* index of first structure to return, set
  92.                  * to first unseen structure on return */
  93.     Ulog_Data *dataPtr;        /* Pointer to array of structures */
  94. {
  95.     int status;
  96.     Db_Handle handle;
  97.     int i;
  98.     register int loc = *locPtr;
  99.     char buffer[ULOG_RECORD_LENGTH];
  100.     Ulog_Data *thisPtr;
  101.     int count;
  102.  
  103.     status = Db_Open(ULOG_FILE_NAME, ULOG_RECORD_LENGTH, &handle, 0,
  104.              DB_LOCK_OPEN, DB_LOCK_BREAK, NUMBUF);
  105.     if (status != 0) {
  106.     return(status);
  107.     }
  108.     i = 0;
  109.     while(i < numEntries) {
  110.     status = Db_Get(&handle, buffer, loc);
  111.     thisPtr = &dataPtr[i];
  112.     /*
  113.      * We go until we get a failure status, then return what we
  114.      * have so far.
  115.      */
  116.     if (status == -1) {
  117.         break;
  118.     }
  119.     count = sscanf(buffer, ULOG_FORMAT_STRING, &thisPtr->uid,
  120.                &thisPtr->hostID, &thisPtr->portID,
  121.                &thisPtr->updated, thisPtr->location);
  122.     /*
  123.      * Only return a record if its updated field is non-zero (i.e.,
  124.      * never initialized or invalidated by being reset to 0.
  125.      * In this case, increment i so the next record goes in the
  126.      * next location, and increment the record number to get.  If
  127.      * sscanf can't parse the record properly, assume it's invalid.
  128.      * It's okay if the location field doesn't match because it
  129.      * may be empty. 
  130.      */
  131.     if (thisPtr->updated != 0 && count >= ULOG_ITEM_COUNT - 1) {
  132.         if (count == ULOG_ITEM_COUNT - 1) {
  133.         thisPtr->location[0] = '\0';
  134.         }
  135.         i++;
  136.     }
  137.     loc++;
  138.     }
  139.     (void) Db_Close(&handle);
  140.     *locPtr = loc;
  141.     return(i);
  142. }
  143. @
  144.  
  145.  
  146. 1.3
  147. log
  148. @allow an empty location field (since it's last in the record, this is
  149. okay).
  150. @
  151. text
  152. @d17 1
  153. a17 1
  154. static char rcsid[] = "$Header: Ulog_GetAllLogins.c,v 1.2 88/09/13 16:43:33 douglis Exp $ SPRITE (Berkeley)";
  155. d47 2
  156. d65 1
  157. a65 1
  158.              DB_LOCK_OPEN, DB_LOCK_BREAK);
  159. @
  160.  
  161.  
  162. 1.2
  163. log
  164. @changed to use ascii representation in database file.
  165. @
  166. text
  167. @d17 1
  168. a17 1
  169. static char rcsid[] = "$Header: Ulog_GetAllLogins.c,v 1.1 88/08/14 15:11:35 douglis Exp $ SPRITE (Berkeley)";
  170. a80 6
  171.     if (count != ULOG_ITEM_COUNT) {
  172.         syslog(LOG_ERR, "Ulog_GetAllLogins: unable to parse record %d",
  173.            loc);
  174.         errno = EACCES;
  175.         return(-1);
  176.     }
  177. d85 4
  178. a88 1
  179.      * next location, and increment the record number to get.
  180. d90 4
  181. a93 1
  182.     if (thisPtr->updated != 0) {
  183. @
  184.  
  185.  
  186. 1.1
  187. log
  188. @Initial revision
  189. @
  190. text
  191. @d17 1
  192. a17 1
  193. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  194. d58 3
  195. d62 1
  196. a62 1
  197.     status = Db_Open(ULOG_FILE_NAME, sizeof(Ulog_Data), &handle, 0,
  198. d69 2
  199. a70 1
  200.     status = Db_Get(&handle, (char *) &dataPtr[i], loc);
  201. d78 9
  202. d93 1
  203. a93 1
  204.     if (dataPtr[i].updated != 0) {
  205. @
  206.